package com.one2manycall.controller;

import com.one2manycall.service.websocket.UserRegistry;
import com.one2manycall.vo.UserSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 用户管理
 */
@Controller
@RequestMapping("/ViewController")
public class ViewController {


    @Autowired
    private UserRegistry userRegistry;


    //// 页面部分 开始  /////////////////////////////////////
    @GetMapping("/home")
    public String listRoles(Model model) {
        return "html/broadcast/view.html";
    }


    @GetMapping("/views")
    @ResponseBody
    public Object getViews() {

        ConcurrentMap<String, UserSession> all = userRegistry.getAll();

        HashMap<String, String> stringStringHashMap = new HashMap<>();

        all.entrySet().stream().forEach(a->stringStringHashMap.put(a.getKey(),a.getValue().getSessionId()));

        return stringStringHashMap;
    }


}